package com.educate.controller;

import com.alibaba.fastjson.JSON;
import com.educate.common.api.Result;
import com.educate.common.api.ResultCode;
import com.educate.pojo.Student;
import com.educate.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ：xqf
 * @date ：Created in 2021/12/21 19:15
 * @description：
 */
@Api(tags = "学生信息管理")
@RestController
@RequestMapping("/student")
public class StudentManagerController {
    @Autowired
    StudentService studentService;
    @ApiOperation("查询学生信息")
    @GetMapping("/allStudents")
    public List<Student> StuManage(){
        List<Student> students = studentService.queryAll();
        return students;
    }
    @ApiOperation("修改学生的电话")
    @GetMapping("/updatePhone")
    public Result updatePhone(String username,String phone){
        if(studentService.updatePhoneNumber(username, phone)){

            return Result.success("修改成功");
        }else {
            return Result.failed("修改失败");
        }


    }
    
    @ApiOperation("根据username,className删除学生信息")
    @GetMapping("/deleteStudent")
    public Result deleteStudent(String username,String className){
        System.out.println("username==>"+username);
        System.out.println("className==>"+className);
        //如国删除成功，就返回状态码200，否则返回状态码500
        if(studentService.deleteStudentByUsernameAndClassName(username,className)){
            return Result.success("删除成功");
        }else{
            return Result.failed("删除失败");
        }
    }
}
